import sys,re,time,thread,threading,os,random
from socket import *
myHost = ''
myPort = 50007

sockobj = socket(AF_INET, SOCK_STREAM)
sockobj.bind((myHost, myPort))
sockobj.listen(5)
lista = []
def thread1():
        connection, address = sockobj.accept()
        print 'Server connected by', address
	lista.append(connection)
        data = connection.recv(1024)
def thread2():
	print 'imprimindo thread 2'
	for x in lista:
		try:
			x.send('se fudeu')
		except socket.error:
			lista.remove(x)
	

def initialize():
	while 1:
		thread.start_new_thread(thread1,())
		time.sleep(1)
		thread.start_new_thread(thread2,())
		time.sleep(1)


initialize()
while 1:
	pass 

